<?php

$objXajax->registerFunction("frmpowertype_loadGrid");
$objXajax->registerFunction("frmpowertype_edit");
$objXajax->registerFunction("frmpowertype_save");
//$objXajax->registerFunction("frmproducttype_fillMenuParent");
    
function frmpowertype_loadGrid(){     

    global $lang,$path;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
    $lang ='vi';
    $arrGrid = frmpowertype_getGrid();
    
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('templates/'.$lang.'/'.$path.'/main_powertype_grid.html');
    $oTbs->MergeBlock('blk_data', $arrGrid);
    $oTbs->Show(TBS_NOTHING);
    $objResponse->addAssign('frmpowertype_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('frmpowertype_tbl');");  
    $objResponse->addScript('changeWaiting(1);');                            
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
}

function  frmpowertype_save($params){
    global $objDbSelect;
    $objResponse = new xajaxResponse();
    $name_vi = addslashes($params['txtNameVi']) ;
    $name_en = addslashes($params['txtNameEn']) ;
    $description = addslashes($params['description']) ;
    $flg_cus = addslashes($params['chkCus']) ;
    $edit  = $params['hdEdit'];
    $id    = $params['hdId'];
    if($edit == 1){
        $sql  = "UPDATE tbl_power_type SET name_vi='$name_vi',flg_cus=$flg_cus,name_en='$name_en',description='$description',date_created=now() where id = '$id'";
    }else{
        $sql  = "INSERT INTO tbl_power_type(name_vi,name_en,description,date_created,flg_cus) value('$name_vi','$name_en','$description',now(),$flg_cus)";
    }
    
    $objDbSelect->Execute($sql);
    $objResponse->addScript('changeWaiting(1);');
    return $objResponse->getXML(); 
} 
  
function  frmpowertype_getGrid(){
    global $objDbSelect;
    $sqlSelect = 'select * from tbl_power_type order by name_vi';
    return $objDbSelect->GetArray($sqlSelect);
}  

function  frmpowertype_edit($id){
    global $objDbSelect;
    $objResponse = new xajaxResponse();
    $sql         = "select * from tbl_power_type where id = $id";
    $arr         = $objDbSelect->GetArray($sql);
    
    $name_vi = $arr[0]['name_vi'];
    $name_en = $arr[0]['name_en'];
    $flg_cus = $arr[0]['flg_cus']==1?'true':'false';       

    
    $description =htmlspecialchars_decode($arr[0]['description']) ;
    $objResponse->addAssign('frmpowertype_description','value',$description); 
             
    $objResponse->addScript("$('#frmpowertype_txtNameVi').val('$name_vi');");
    $objResponse->addScript("$('#frmpowertype_txtNameEn').val('$name_en');");
    $objResponse->addScript("$('#frmpowertype_chkCus').attr('checked',$flg_cus);"); 
       
    $objResponse->addScript('changeWaiting(1);');
    
    return $objResponse->getXML();
} 

function  frmpowertype_delete($id){
    global $lang;
    $objResponse = new xajaxResponse();
    return $objResponse->getXML();
}


# end region process data
?>
